package com.cx.service.admin.basic.impl;

import com.cx.dao.impl.ChainJKTDaoSupport;
import com.cx.service.admin.basic.LoginManager;
import org.cx.entity.PageData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

@Service("loginService")
public class LoginService implements LoginManager {
    @Resource(name = "chainJKTDaoSupport")
    private ChainJKTDaoSupport chainJKTDao;

    private Logger logger = LoggerFactory.getLogger(LoginService.class);

    private static ThreadLocal<PageData> virtualUser = new ThreadLocal<>();

    @Override
    public PageData findUserInfo(PageData pd) {
        List<PageData> list = (List<PageData>) chainJKTDao.findForList("UserMapper.findUserRoleByUserPhone",pd);
        if(!list.isEmpty()){
            return  list.get(0);
        }
        return null;
    }
    @Override
    public List<PageData> findUserInfoList(PageData pd) {
        List<PageData> list = (List<PageData>) chainJKTDao.findForList("UserMapper.findUserRoleByUserPhone",pd);
        return list;
    }

    @Override
    public List<PageData> findUserPrivileges(PageData pd) throws Exception {
        List<PageData> list = (List<PageData>) chainJKTDao.findForList("PrivilegeMapper.findPrivilegeDetailByUser",pd);

        return list;
    }

    @Override
    public PageData insertLog(PageData pd) throws Exception {
        pd = chainJKTDao.saveBackPageData("LogOperationMapper.insertLog",pd);
        return null;
    }


}
